<%--
Document : index.jsp
Created on : 21.11.2014, 22:32:19
Author : David Katuscak, 359273
--%>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>


<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title><fmt:message key="machine.index.title" /></title>
    </head>
    <body>
        <div class="container">
            <h1><fmt:message key="machine.index.title" /></h1>
            <div>
                <a href="<c:url value="/machine/add"/>">
                    <img src="<c:url value="/resources/pictures/add.png" />" title="<fmt:message key="machine.addNew" />" /> <fmt:message key="machine.addNew" />
                </a>
            </div>

            <c:if test="${empty model.machines}">
                <fmt:message key="machine.index.noMachines" />
            </c:if>
            <c:if test="${not empty model.machines}">
                <form method="POST" class="form-inline" role="form">
                    <div class="form-group">
                        <label for="searchBy"><fmt:message key="machine.index.searchBy" /></label>
                        <select name="searchBy" id="searchBy" class="form-control">
                            <option value="brand" <c:if test="${empty model.searchBy}"> selected="selected"</c:if> <c:if test="${model.searchBy == 'brand'}"> selected="selected"</c:if>><fmt:message key="machine.index.brand" /></option>
                            <option value="code" <c:if test="${model.searchBy == 'code'}"> selected="selected"</c:if>><fmt:message key="machine.index.code" /></option>
                            <option value="model" <c:if test="${model.searchBy == 'model'}"> selected="selected"</c:if>><fmt:message key="machine.index.model" /></option>
                            </select>
                        </div>
                        <div class="form-group">
                            <input type="text" class="form-control" name="search" <c:if test="${not empty model.search}"> value="${model.search}"</c:if>>
                        </div>
                        <div class="form-group">
                            <input class="btn btn-default" type="submit" value="<fmt:message key="search"/>">
                    </div>
                </form>

                <table class="table table-striped">
                    <th>
                        <fmt:message key="detail" />
                    </th>
                    <th>
                        <fmt:message key="machine.code" />
                    </th>
                    <th>
                        <fmt:message key="machine.brand" />
                    </th>
                    <th>
                        <fmt:message key="machine.model" />
                    </th>
                    <th>
                        <fmt:message key="machine.yearOfProduction" />
                    </th>
                    <th>
                        <fmt:message key="edit" />
                    </th>
                    <c:forEach var="m" items="${model.machines}">
                        <tr>
                            <td>
                                <a href="<c:url value="/machine/detail/${m.id}"/>">
                                    <img src="<c:url value="/resources/pictures/detail.png" />" title="<fmt:message key="detail" />" /> <fmt:message key="detail" />
                                </a>
                            </td>
                            <td>
                                <a href="<c:url value="/machine/detail/${m.id}"/>"><c:out value="${m.code}"/></a>
                            </td>
                            <td>
                                <c:out value="${m.brand}"/>
                            </td>
                            <td>
                                <c:out value="${m.model}"/>
                            </td>
                            <td>
                                <c:out value="${m.yearOfProduction}"/>
                            </td>
                            <td>
                                <a href="<c:url value="/machine/edit/${m.id}"/>">
                                    <img src="<c:url value="/resources/pictures/edit.png" />" title="<fmt:message key="edit" />" /> <fmt:message key="edit" />
                                </a>
                            </td>
                        </tr>
                    </c:forEach>
                </table>
            </c:if>
        </div>
    </body>
</html>